////////////////////////////////////////////////////////////////////////////
/// Name: main.cpp
/// Author: B. Gian James <gian@BattleDroids.net>
// Description: This is the main file.
///
/// $Id: main.cpp,v 1.2 2009/08/28 22:55:17 gian Exp $
////////////////////////////////////////////////////////////////////////////
#include "common.h"
#include "protocol.h"
#include "uart.h"
#include "droid.h"
#include <stdlib.h>
#include <avr/interrupt.h>
#include "cmds.h"

static UART			uart(Baud9600,(UART_TX|UART_RX));

int main(void)
{
	uart.EnableInterrupt(UART_RX);
	sei();
	
	BattleDroid		droid;
	
	if (!droid.Init()) {
		PPkt p(CMD_CONFIG);
		UART::TXPacket(p);
	} else
		;

	for (;;)
	{
		if (TCNT1 > CHECK_TIME)
		{
			StopTimer();
			ClearTimer();
			
			UART::tx(uart.GetFromReceive());
		}
	}
}

ISR(USART_RX_vect)
{
	StopTimer();
	ClearTimer();
	
	uchar c = UART::rx();
	uart.AddToReceive(c);
	
	StartTimer();
}
